package com.base.vistter.iframe.inverter.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.base.vistter.iframe.bean.Result;
import com.base.vistter.iframe.entity.InverterAlarmDetails;
import com.base.vistter.iframe.exception.IframeException;
import com.base.vistter.iframe.service.InverterAlarmDetailsService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/alarm/details")
public class InverterAlarmDetailsController {
    @Resource(name = "inverterAlarmDetailsService")
    private InverterAlarmDetailsService inverterAlarmDetailsService;

    @GetMapping
    public Result<Page<InverterAlarmDetails>> get(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(value = "pageNum", defaultValue = "10") Integer pageNum, Integer status, Integer stationId) throws IframeException {
        Page<InverterAlarmDetails> page = Page.of(pageNo, pageNum);
        return Result.ok(inverterAlarmDetailsService.pageInverterAlarmDetails(page, status, stationId));
    }

    @GetMapping("/{id}")
    public Result<InverterAlarmDetails> get(@PathVariable("id") Integer id) throws IframeException {
        return Result.ok(inverterAlarmDetailsService.getInverterAlarmDetailsById(id));
    }

    @GetMapping("/recover")
    public Result<Boolean> recover(Integer alarmId) throws IframeException {
        return Result.ok(inverterAlarmDetailsService.recover(alarmId));
    }

    @GetMapping("/devices")
    public Result<List<InverterAlarmDetails>> getByDevicesId(Integer devicesId) {
        return Result.ok(inverterAlarmDetailsService.getByDevicesId(devicesId));
    }

}
